General

Components

Community

Development

TDF

Documents > Cookbook >Manipulate Metadata



Overview
This Meta API supports to access and set document metadata. It covers the metadata definitions in ODF Specification 1.2 Committee Draft05

Get Meta object
First you load an ODF text document(for example),then get the meta file DOM and then use the meta DOM to create an instance of the Meta. Use Meta you can access all the supported elements.

	TextDocument doc = (TextDocument) TextDocument.loadDocument("testtable.odt");
OdfFileDom metadom = doc.getMetaDom();
Meta metadata = new Meta(metadom);


Access metadata
After creating the Meta instance,you can use it to manipulate the metadata: for example, you can set a value for the <meta:generator> like this:

	metadata.setGenerator("OpenOffice.org/3.0$Win32 OpenOffice.org_project/300m15$Build-9379");

The <meta:keyword> may contain many keywords, you can set the whole list of keywords and add one keyword as you want. the api currently do not provide the direct method for deleting one keyword ,you can get the keyword list first,and then delete the keyword,finally set the list to the element.

       metadata.addKeyword("java");
List<String> keywords=metadata.getKeywords();
keywords.remove("java");
metadata.setKeywords(keywords);


Access the user defined element
To manipulate the user defined data,you should get the list of their names,and then use the names to update the data or its datatype or delete the whole user defined data. you can use the setUserDefinedData(String name, String type, String value) method to update data,if the name not exists in the document,the method will add the new user defined data.

      List<String> names=metadata.getUserDefinedDataNames();
for (String name : names) {
metadata.removeUserDefinedDataByName(name);
}
String key="newId";
//org.odftoolkit.odfdom.dom.attribute.meta.MetaValueTypeAttribute.Value metadata.setUserDefinedData(key, Value.STRING.toString(), "new001");
//update the datatype metadata.setUserDefinedDataType(key, Value.BOOLEAN.toString());
//update the data value metadata.setUserDefinedDataValue(key, "false");

//get the datatype String dataType=metadata.getUserDefinedDataType(key);
//get the data value String dataValue=metadata.getUserDefinedDataValue(key);


Access the document statistics
if you want to access the document statistics,you should get a DocumentStatistic instance, if the return is null,it means that this ODF document doesn't have any document statistic information,you should create a document statistics object.

	DocumentStatistic stat = metadata.getDocumentStatistic();
if(stat==null) {
stat=new DocumentStatistic(metadata.getOfficeMetaElement().newMetaDocumentStatisticElement());
}

stat.setCellCount(3);
Integer cellCount=stat.getCellCount();


Impressum (Legal Info) | Privacy Policy (Datenschutzerklärung) | Statutes (non-binding English translation) - Satzung (binding German version) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Apache License, v2.0. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License v2.0. “LibreOffice” and “The Document Foundation” are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy. LibreOffice was based on OpenOffice.org.